﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DingTalkAgent.Model;
using DingTalkAgent.DBUtility;
namespace DingTalkAgent.Web.Models
{
    public class buildSelect
    {
        /// <summary>
        /// 获取字典信息
        /// 
        /// </summary>
        /// <param name="list"></param>
        /// <param name="selecvalue"></param>
        /// <returns></returns>
        public static IEnumerable<System.Web.Mvc.SelectListItem> DictionaryList(IEnumerable<Model.Dictionary> list, string selecvalue)
        {
            System.Web.Mvc.SelectListItem m;
            foreach (var l in list)
            {
                m = new System.Web.Mvc.SelectListItem();
                m.Text = l.Name;
                m.Value = l.Dic_ID.ToString();
                if (m.Value == selecvalue)
                {
                    m.Selected = true;
                }
                yield return m;
            }
        }
        public static List<System.Web.Mvc.SelectListItem> getDictionaryList(IEnumerable<Model.Dictionary> list, string selecvalue)
        {
            return buildSelect.DictionaryList2(list, selecvalue).ToList();
        }
        /// <summary>
        /// 获取字典信息
        /// 这里Vlaue直接绑定了Name其它有特别需求，注意修改
        /// </summary>
        /// <param name="list"></param>
        /// <param name="selecvalue"></param>
        /// <returns></returns>
        public static System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem> DictionaryList2(IEnumerable<Model.Dictionary> list, string selecvalue)
        {
            System.Web.Mvc.SelectListItem m;
            foreach (var l in list)
            {
                m = new System.Web.Mvc.SelectListItem();
                m.Text = l.Name;
                m.Value = l.Name.ToString();
                if (m.Value == selecvalue)
                {
                    m.Selected = true;
                }
                yield return m;
            }
        }



        public static IEnumerable<System.Web.Mvc.SelectListItem> RoleList(IEnumerable<DingTalkAgent.Model.Roles> list, string selecvalue)
        {
            System.Web.Mvc.SelectListItem m;
            foreach (var l in list)
            {
                m = new System.Web.Mvc.SelectListItem();
                m.Text = l.Name;
                m.Value = l.ID.ToString();
                if (m.Value == selecvalue)
                {
                    m.Selected = true;
                }
                yield return m;
            }
        }



        /// <summary>
     

    }
}